﻿using CSC.Managers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace JDGLSys.Forms.Pages.AdminFormPages
{
    /// <summary>
    /// FoodsPage.xaml 的交互逻辑
    /// </summary>
    public partial class FoodsPage : Page
    {
        public FoodsPage()
        {
            InitializeComponent();

        }

        private void Updatas_Click(object sender, RoutedEventArgs e)
        {
            DataGrid.ItemsSource =
            FoodsTManager.ShowDataTable().DefaultView;

            //更改datagrid标题      Foods表共3列
            DataGrid.Columns[0].Header = "菜品id";
            DataGrid.Columns[1].Header = "菜品名";
            DataGrid.Columns[2].Header = "价格";

        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //默认显示表格内容
            DataGrid.ItemsSource =
            FoodsTManager.ShowDataTable().DefaultView;
            //更改datagrid标题      Foods表共3列
            DataGrid.Columns[0].Header = "菜品id";
            DataGrid.Columns[1].Header = "菜品名";
            DataGrid.Columns[2].Header = "价格";
        }

        private void UpdateBtn_Click(object sender, RoutedEventArgs e)
        {
            FoodsTManager.UpdateSqlDBBuilder();
            MessageBox.Show("数据已更新到库");
        }

        private void deleteBtn_Click(object sender, RoutedEventArgs e)
        {
            //删除所选择相关记录
            MessageBoxResult r = MessageBox.Show("你确定要删除吗？", "信息提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (r == MessageBoxResult.Yes)
            {
                DataRowView drv = DataGrid.SelectedItem as DataRowView;
                drv.Delete();

                FoodsTManager.UpdateSqlDBBuilder();
                MessageBox.Show("所选记录已全部删除");
            }
            else return;
        }

    }
}
